package com.ruoyi.logistic.controller;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.logistic.domain.NetworkBillDetail;
import com.ruoyi.logistic.domain.PageDate;
import com.ruoyi.logistic.domain.PageInfo;
import com.ruoyi.logistic.domain.vo.NetworkBillDetailVo;
import com.ruoyi.logistic.service.NetworkBillDetailService;
import com.ruoyi.logistic.service.impl.NetworkBillDetailServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.sql.Date;
import java.util.List;

@RequestMapping("/network/collectBill")
@RestController
@Api(tags = "网点财务_网点揽收分润账单_账单明细")
public class NetworkBillDetailController {
    @Autowired
    private NetworkBillDetailService networkBillDetailService;

    @ApiOperation("显示网点揽收分润账单_账单明细")
    @GetMapping("/selectAll")
    public R selectAll(PageDate pageDate){
        List<NetworkBillDetail> networkBillDetailList = networkBillDetailService.selectAll(pageDate);
        if (networkBillDetailList == null || networkBillDetailList.size() == 0){
            return R.fail("暂无数据");
        }else {
            return R.ok(PageInfo.info(networkBillDetailList));
        }
    }
    @ApiOperation("添加网点揽收分润账单_账单明细")
    @PostMapping("/insert")
    public R insert(@RequestBody NetworkBillDetail networkBillDetail){
        Boolean isAdd = networkBillDetailService.insert(networkBillDetail);
        if (isAdd){
            return R.ok("添加成功");
        }else {
            return R.fail("添加失败");
        }
    }
    @ApiOperation("修改网点揽收分润账单_账单明细")
    @PostMapping("/update")
    public R update(@RequestBody NetworkBillDetail networkBillDetail){
        Boolean isUpdate = networkBillDetailService.update(networkBillDetail);
        if (isUpdate){
            return R.ok("修改成功");
        }else {
            return R.fail("修改失败");
        }
    }
    @ApiOperation("删除网点揽收分润账单_账单明细")
    @PostMapping("/deleteById")
    public R deleteById(Integer id){
        Boolean isDelete = networkBillDetailService.deleteById(id);
        if (isDelete){
            return R.ok("删除成功");
        }else {
            return R.fail("删除失败");
        }
    }
    @ApiOperation("搜索网点揽收分润账单_账单明细")
    @PostMapping("/search")
    public R search(@RequestBody NetworkBillDetailVo networkBillDetailVo){
        if (networkBillDetailVo.getNetworkNameId() == null || networkBillDetailVo.getCollectType() == null){
            return R.fail("汇总维度和网点信息为必传字段！");
        }
        List<NetworkBillDetail> networkBillDetailList = networkBillDetailService.search(networkBillDetailVo);
        if (networkBillDetailList == null || networkBillDetailList.size() == 0){
            return R.fail("暂无数据");
        }else {
            return R.ok(PageInfo.info(networkBillDetailList));
        }
    }

}
